package io.github.lee.app.unsplash.ui.main.home.page

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import coil.load
import io.github.lee.app.unsplash.databinding.HeaderTopicPhotoBinding
import io.github.lee.app.unsplash.repository.domain.DEFAULT_BLUR_HASH
import io.github.lee.app.unsplash.repository.domain.Topic
import io.github.lee.app.unsplash.util.BlurHashDecoder
import io.github.lee.core.ui.adapter.HeaderFooterAdapter

class TopicPhotoHeaderAdapter(data: Topic?) :
    HeaderFooterAdapter<Topic, HeaderTopicPhotoBinding>(data) {
    override fun onCreateDataBinding(
        context: Context,
        inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): HeaderTopicPhotoBinding =
        HeaderTopicPhotoBinding.inflate(inflater, parent, false)

    override fun onItemHolder(binding: HeaderTopicPhotoBinding, item: Topic) {
        val hash = BlurHashDecoder.decode(item.coverPhoto?.blurHash ?: DEFAULT_BLUR_HASH, 6, 5)
        binding.ivCover.load(hash)
        binding.rlRatio.ratio = 1.2F
        binding.topic = item
    }

}
//class TopicPhotoHeaderAdapter(topic: Topic?) :
//    BaseSingleItemAdapter<Topic, DataBindingHolder<HeaderTopicPhotoBinding>>(topic) {
//    override fun onBindViewHolder(
//        holder: DataBindingHolder<HeaderTopicPhotoBinding>,
//        item: Topic?
//    ) {
//        if (null == item) {
//            return
//        }

//    }
//
//
//    override fun onCreateViewHolder(
//        context: Context,
//        parent: ViewGroup,
//        viewType: Int
//    ): DataBindingHolder<HeaderTopicPhotoBinding> =
//        DataBindingHolder(
//            HeaderTopicPhotoBinding.inflate(
//                LayoutInflater.from(context),
//                parent,
//                false
//            )
//        )
//}